package com.lq.leetcode;

import java.util.LinkedList;
import java.util.List;
import java.util.Stack;

/**
 * Solution
 *
 * @author qingqing
 * @date 2024/12/17
 */

public class Solution {
//    public List<List<Integer>> threeSum(int[] nums) {
//        for (int i = 0; i < nums.length; i++) {
//            int l = i + 1;
//            int r = nums.length - 1;
//            while (l < r) {
//                if ()
//            }
//        }
//    }

    public int findDuplicate(int[] nums) {

        for (int i = 0; i < nums.length; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                if (nums[i] == nums[j]) {
                    return nums[i];
                }
            }
        }
        return 0;
    }

    // 739
    public int[] dailyTemperatures(int[] temperatures) {
        int[] res = new int[temperatures.length];
        Stack<Integer> stack = new Stack<>();
        for (int i = 0; i < temperatures.length; i++) {
            if (stack.size() == 0 || temperatures[i] <= temperatures[stack.peek()]) {
                stack.push(i);
            } else {
                while (stack.size() != 0 && temperatures[stack.peek()] < temperatures[i]) {
                    int idx = stack.pop();
                    res[idx] = i - idx;
                }
                stack.push(i);
            }
        }
        return res;
    }

    // 1143
    public List<Boolean> kidsWithCandies(int[] candies, int extraCandies) {
        List<Boolean> res = new LinkedList<>();
        int max = 0;
        for (int i = 0; i < candies.length; i++) {
            max = Math.max(max, candies[i]);
        }
        for (int i = 0; i < candies.length; i++) {
            if (candies[i] + extraCandies >= max) {
                res.add(true);
            } else {
                res.add(false);
            }
        }
        return res;
    }

    // 15
    
}
